package io.github.voishion.redismq.example.component;

import io.github.voishion.redismq.RedisDelayMQListener;
import io.github.voishion.redismq.RedisDelayMQMessage;
import io.github.voishion.redismq.RedisMQListener;
import io.github.voishion.redismq.RedisMQMessage;
import io.github.voishion.redismq.core.RedisMQException;
import io.github.voishion.redismq.example.constant.RedisMQConstant;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

/**
 * @author lilu
 */
@Log4j2
@Component
public class RedisDelayMQListenerContainer {

    @RedisDelayMQListener(RedisMQConstant.TEST_DELAY_QUEUE)
    public void dealRedisMessage0(RedisDelayMQMessage<String> message) {
        String payload = message.getPayload();
        if ("11".equals(payload)) {
            if (5 != message.getFailNumber()) {
                throw new RedisMQException("消费异常啦...");
            }
        }
        if ("111".equals(payload)) {
            throw new RedisMQException("消费异常啦...");
        }
        log.info("dealRedisMessage0收到queue-1队列消息: {}", message);
    }

    @RedisDelayMQListener(RedisMQConstant.TEST_DELAY_QUEUE_2)
    public void dealRedisMessage2(RedisDelayMQMessage<String> message) {
        log.info("dealRedisMessage0收到queue-2队列消息: {}", message);
    }

}
